package com.gitee.ykr.lightweight.rpc.config.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.StringUtils;

/**
 * @author YKR
 * @Describe
 * @date 2021/8/24
 */
public class PropertyContainsCondition implements Condition {

    String key;

    public PropertyContainsCondition(String key) {
        this.key = key;
    }

    //matches方法返回true，装配bean，返回false，不装配bean
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String value = context.getEnvironment().getProperty( key );
        return StringUtils.isEmpty( value ) ? false : true;
    }
}